//
//  UIImage+clip.m
//  Catus
//
//  Created by 晓梦影 on 16/4/26.
//  Copyright © 2016年 黄金星. All rights reserved.
//

#import "UIImage+clip.h"

@implementation UIImage (clip)

/** 返回一张圆形裁剪后图片*/
+ (instancetype)clipWith:(UIImage *)image{
    //1.加载图片
//    UIImage *image =  [UIImage imageNamed:@"head"];
    //2.开启一个位图上下文
    UIGraphicsBeginImageContext(image.size);
    //3.设置裁剪区域
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
    //4.把路径设置成裁剪区域
    [path addClip];
    
    //5.把图片绘制到上下文当中
    [image drawAtPoint:CGPointZero];
    
    //6.从上下文当中生成一张图片
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    //7.关闭位图上下文
    UIGraphicsEndImageContext();
    
    return newImage;
}
@end
